<html>
 <head>
  <meta charset="UTF-8">
 </head>
 <body>
  <h1 data-lake-id="TDvTH" id="TDvTH"><span data-lake-id="u2d42c874" id="u2d42c874">典型回答</span></h1>
  <p data-lake-id="u4d40df8b" id="u4d40df8b"><br></p>
  <p data-lake-id="u1e57bb89" id="u1e57bb89"><span data-lake-id="u867fffed" id="u867fffed">InnoDB和MyISAM是MySQL中比较常用的两个执行引擎，</span><span data-lake-id="ud6be6ec8" id="ud6be6ec8" style="color: rgb(51, 51, 51)">MySQL 在 5.5 之前版本默认存储引擎是 MyISAM，5.5 之后版本默认存储引擎是 InnoDB，MyISAM适合查询以及插入为主的应用，InnoDB适合频繁修改以及涉及到安全性较高的应用。</span></p>
  <p data-lake-id="ucd99073e" id="ucd99073e"><span data-lake-id="u0932c979" id="u0932c979">​</span><br></p>
  <blockquote data-lake-id="u2b99ea97" id="u2b99ea97">
   <ul list="u1942d5bf">
    <li fid="uc2943337" data-lake-id="u10e0eb42" id="u10e0eb42"><span data-lake-id="ue9c55f17" id="ue9c55f17">如果应用需要高度的数据完整性和事务支持，那么InnoDB是更好的选择。所以频繁修改及数据安全性的情况适合。</span></li>
    <li fid="uc2943337" data-lake-id="ue59bacef" id="ue59bacef"><span data-lake-id="u165d5d4c" id="u165d5d4c">如果应用主要是读取操作，或者需要高效的全文搜索功能，那么MyISAM可能更适合。所以查询频繁的适合。</span></li>
   </ul>
  </blockquote>
  <p data-lake-id="uc952f5e9" id="uc952f5e9"><span data-lake-id="u7dbbec1a" id="u7dbbec1a">​</span><br></p>
  <p data-lake-id="ub0c00232" id="ub0c00232"><span data-lake-id="u9f0d51ea" id="u9f0d51ea">他们主要有以下区别：</span></p>
  <p data-lake-id="u1ebb957f" id="u1ebb957f"><br></p>
  <ul list="uec765449">
   <li fid="u5a3e2d2a" data-lake-id="ud0d246a5" id="ud0d246a5"><span data-lake-id="u17c1fae0" id="u17c1fae0" style="color: rgb(51, 51, 51)">一、</span><strong><span data-lake-id="ue970c43e" id="ue970c43e" style="color: rgb(51, 51, 51)">InnoDB支持事务</span></strong><span data-lake-id="ua956e278" id="ua956e278" style="color: rgb(51, 51, 51)">，MyISAM不支持</span></li>
   <li fid="u5a3e2d2a" data-lake-id="u97f1fd41" id="u97f1fd41"><span data-lake-id="ua0f9fecc" id="ua0f9fecc" style="color: rgb(18, 18, 18)">二、</span><strong><span data-lake-id="u03dae072" id="u03dae072" style="color: rgb(18, 18, 18)">InnoDB 是聚集索引</span></strong><span data-lake-id="ubf778a42" id="ubf778a42" style="color: rgb(18, 18, 18)">，MyISAM 是非聚集索引。MyISAM是采用了一种索引和数据分离的存储方式，Innodb的聚簇索引中索引和数据在一起。</span></li>
   <li fid="u5a3e2d2a" data-lake-id="u1b89a5aa" id="u1b89a5aa"><span data-lake-id="u0b88e86d" id="u0b88e86d" style="color: rgb(51, 51, 51)">三、</span><strong><span data-lake-id="u930acd3c" id="u930acd3c" style="color: rgb(51, 51, 51)">InnoDB支持外键</span></strong><span data-lake-id="u1484d7c5" id="u1484d7c5" style="color: rgb(51, 51, 51)">，MyISAM不支持</span></li>
   <li fid="u5a3e2d2a" data-lake-id="u7fa8eef0" id="u7fa8eef0"><span data-lake-id="u2a4a2003" id="u2a4a2003" style="color: rgb(18, 18, 18)">四、</span><strong><span data-lake-id="uba0bff47" id="uba0bff47" style="color: rgb(18, 18, 18)">InnoDB 最小的锁粒度是行锁</span></strong><span data-lake-id="uc3af4a78" id="uc3af4a78" style="color: rgb(18, 18, 18)">，MyISAM 最小的锁粒度是表锁。</span></li>
   <li fid="u5a3e2d2a" data-lake-id="ub4e0e004" id="ub4e0e004"><span data-lake-id="u42c0a235" id="u42c0a235" style="color: rgb(51, 51, 51)">五、</span><strong><span data-lake-id="u280c470a" id="u280c470a" style="color: rgb(51, 51, 51)">InnoDB不支持FULLTEXT类型的索引（5.6之前不支持全文索引）</span></strong></li>
   <li fid="u5a3e2d2a" data-lake-id="uf5bd379b" id="uf5bd379b"><span data-lake-id="u48698745" id="u48698745" style="color: rgb(51, 51, 51)">六、</span><strong><span data-lake-id="u62fb6179" id="u62fb6179" style="color: rgb(51, 51, 51)">InnoDB中不保存表的行数</span></strong><span data-lake-id="ua5f7b72f" id="ua5f7b72f" style="color: rgb(51, 51, 51)">，但是MyISAM只要简单的读出保存好的行数即可</span></li>
   <li fid="u5a3e2d2a" data-lake-id="u697f9912" id="u697f9912"><span data-lake-id="u9de789ca" id="u9de789ca" style="color: rgb(51, 51, 51)">七、对于自增长的字段，InnoDB中必须包含只有该字段的索引，但是在MyISAM表中可以和其他字段一起建立联合索引</span></li>
   <li fid="u5a3e2d2a" data-lake-id="ud4d4ecec" id="ud4d4ecec"><span data-lake-id="uc80c0e84" id="uc80c0e84" style="color: rgb(51, 51, 51)">八、清空整个表时，InnoDB是一行一行的删除，效率非常慢。MyISAM则会重建表</span></li>
  </ul>
  <p data-lake-id="u2985671f" id="u2985671f"><span data-lake-id="ud114f6a3" id="ud114f6a3" style="color: rgb(51, 51, 51)">​</span><br></p>
  <table data-lake-id="TmAIH" id="TmAIH" margin="true" width-mode="contain" class="lake-table" style="width: 746px">
   <colgroup>
    <col width="248">
    <col width="249">
    <col width="249">
   </colgroup>
   <tbody>
    <tr data-lake-id="u4599716c" id="u4599716c" style="height: 36px">
     <td data-lake-id="u27dfabe2" id="u27dfabe2">
      <p data-lake-id="u9d6fe954" id="u9d6fe954"><strong><span data-lake-id="u7e067b41" id="u7e067b41">​</span></strong><br></p></td>
     <td data-lake-id="ua47400fe" id="ua47400fe">
      <p data-lake-id="ufaccb29d" id="ufaccb29d"><strong><span data-lake-id="u8d25ff43" id="u8d25ff43">InnoDB</span></strong></p></td>
     <td data-lake-id="u183b265f" id="u183b265f">
      <p data-lake-id="u7f171343" id="u7f171343"><strong><span data-lake-id="u7897f52e" id="u7897f52e">MyISAM</span></strong></p></td>
    </tr>
    <tr data-lake-id="ud070777b" id="ud070777b">
     <td data-lake-id="uc066538f" id="uc066538f">
      <p data-lake-id="u1a1725fb" id="u1a1725fb"><strong><span data-lake-id="ud4772730" id="ud4772730">事务</span></strong></p></td>
     <td data-lake-id="u97f90bc0" id="u97f90bc0">
      <p data-lake-id="ueb7918f6" id="ueb7918f6"><span data-lake-id="u5a027db0" id="u5a027db0">支持</span></p></td>
     <td data-lake-id="u6de88449" id="u6de88449">
      <p data-lake-id="uc2185333" id="uc2185333"><span data-lake-id="ue298fc1b" id="ue298fc1b">不支持</span></p></td>
    </tr>
    <tr data-lake-id="u9d4073ad" id="u9d4073ad" style="height: 36px">
     <td data-lake-id="ua2e8b7a0" id="ua2e8b7a0">
      <p data-lake-id="ufc918533" id="ufc918533"><strong><span data-lake-id="u00b5281f" id="u00b5281f">外键</span></strong></p></td>
     <td data-lake-id="u393f5522" id="u393f5522">
      <p data-lake-id="uff1cd807" id="uff1cd807"><span data-lake-id="u4538e953" id="u4538e953">支持</span></p></td>
     <td data-lake-id="ub7c7053f" id="ub7c7053f">
      <p data-lake-id="u99064a34" id="u99064a34"><span data-lake-id="ua4069d0d" id="ua4069d0d">不支持</span></p></td>
    </tr>
    <tr data-lake-id="uccddd7e5" id="uccddd7e5" style="height: 36px">
     <td data-lake-id="u9de2f3f0" id="u9de2f3f0">
      <p data-lake-id="ue8733979" id="ue8733979"><strong><span data-lake-id="u94b7e5f3" id="u94b7e5f3">聚簇索引</span></strong></p></td>
     <td data-lake-id="ub8a5b5a8" id="ub8a5b5a8">
      <p data-lake-id="ua3498cc8" id="ua3498cc8"><span data-lake-id="u2be898bd" id="u2be898bd">支持</span></p></td>
     <td data-lake-id="u312c1011" id="u312c1011">
      <p data-lake-id="ub9c281bd" id="ub9c281bd"><span data-lake-id="ubddf23d3" id="ubddf23d3">不支持</span></p></td>
    </tr>
    <tr data-lake-id="u18cd09be" id="u18cd09be">
     <td data-lake-id="u6f92ebd6" id="u6f92ebd6">
      <p data-lake-id="u774d47c1" id="u774d47c1"><strong><span data-lake-id="ub9a4434a" id="ub9a4434a">锁级别</span></strong></p></td>
     <td data-lake-id="ub49bad47" id="ub49bad47">
      <p data-lake-id="udc398885" id="udc398885"><span data-lake-id="ube10122f" id="ube10122f">支持行级锁、表级锁</span></p></td>
     <td data-lake-id="u95235414" id="u95235414">
      <p data-lake-id="u6bc4efff" id="u6bc4efff"><span data-lake-id="uc2129f52" id="uc2129f52">表级锁</span></p></td>
    </tr>
    <tr data-lake-id="u99d9f123" id="u99d9f123">
     <td data-lake-id="udf96e5f0" id="udf96e5f0">
      <p data-lake-id="u5d7fd9db" id="u5d7fd9db"><strong><span data-lake-id="uac25664d" id="uac25664d">行数保存</span></strong></p></td>
     <td data-lake-id="uad9dafbd" id="uad9dafbd">
      <p data-lake-id="u126df5b7" id="u126df5b7"><span data-lake-id="u91a83deb" id="u91a83deb">不支持</span></p></td>
     <td data-lake-id="u8ebe1a70" id="u8ebe1a70">
      <p data-lake-id="u9c193d3d" id="u9c193d3d"><span data-lake-id="uae237c62" id="uae237c62">支持</span></p></td>
    </tr>
    <tr data-lake-id="u2aaff677" id="u2aaff677">
     <td data-lake-id="u5f787bd8" id="u5f787bd8">
      <p data-lake-id="u25891a05" id="u25891a05"><strong><span data-lake-id="u1968dbf9" id="u1968dbf9">清空方式</span></strong></p></td>
     <td data-lake-id="u01756c3d" id="u01756c3d">
      <p data-lake-id="u695e67f1" id="u695e67f1"><span data-lake-id="uebcb6ff5" id="uebcb6ff5" style="color: rgb(51, 51, 51)">逐行删除</span></p></td>
     <td data-lake-id="u8b98c11d" id="u8b98c11d">
      <p data-lake-id="u15b46957" id="u15b46957"><span data-lake-id="u4c9958f8" id="u4c9958f8" style="color: rgb(51, 51, 51)">重建表</span></p></td>
    </tr>
    <tr data-lake-id="u7aa41d2c" id="u7aa41d2c">
     <td data-lake-id="ucac2d56e" id="ucac2d56e">
      <p data-lake-id="u7db2d85f" id="u7db2d85f"><strong><span data-lake-id="u3b3d0c30" id="u3b3d0c30">默认版本</span></strong></p></td>
     <td data-lake-id="ue76b9da7" id="ue76b9da7">
      <p data-lake-id="u03cdd7e4" id="u03cdd7e4"><span data-lake-id="u3ed67230" id="u3ed67230" style="color: rgb(51, 51, 51)">5.5 之后</span></p></td>
     <td data-lake-id="u1ff4f92b" id="u1ff4f92b">
      <p data-lake-id="u1c0fba0e" id="u1c0fba0e"><span data-lake-id="u0e4d7d4a" id="u0e4d7d4a" style="color: rgb(51, 51, 51)">5.5 之前</span></p></td>
    </tr>
    <tr data-lake-id="u8f2f056e" id="u8f2f056e">
     <td data-lake-id="u6ef922df" id="u6ef922df">
      <p data-lake-id="u7bc9f591" id="u7bc9f591"><strong><span data-lake-id="uace58c91" id="uace58c91">全文索引</span></strong></p></td>
     <td data-lake-id="u30ad64a2" id="u30ad64a2">
      <p data-lake-id="u87f74d2d" id="u87f74d2d"><span data-lake-id="u01cf9202" id="u01cf9202">5.6以后支持</span></p></td>
     <td data-lake-id="u93dba43f" id="u93dba43f">
      <p data-lake-id="u46945b93" id="u46945b93"><span data-lake-id="ua08b692f" id="ua08b692f">支持</span></p></td>
    </tr>
   </tbody>
  </table>
  <p data-lake-id="uf88a685f" id="uf88a685f"><span data-lake-id="u6826c6fe" id="u6826c6fe" style="color: rgb(51, 51, 51)">​</span><br></p>
  <h1 data-lake-id="UzMm0" id="UzMm0"><span data-lake-id="u3a28529a" id="u3a28529a" style="color: rgb(51, 51, 51)">扩展知识</span></h1>
  <p data-lake-id="u3d9950a7" id="u3d9950a7"><br></p>
  <h2 data-lake-id="zrwBL" id="zrwBL"><span data-lake-id="u7f832b9f" id="u7f832b9f">索引结构区别</span></h2>
  <p data-lake-id="u46711f9f" id="u46711f9f"><br></p>
  <p data-lake-id="u9d3030ce" id="u9d3030ce"><span data-lake-id="u441bec60" id="u441bec60"><br></span><span data-lake-id="ua7d94ac9" id="ua7d94ac9"> </span></p>
 </body>
</html>